package demo04;

import com.itcv.util.FileUtils;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;

import static org.objectweb.asm.Opcodes.ASM9;

public class TestRemovePrintMain {

    public static void main(String[] args) {
       TestRemovePrintMain test = new TestRemovePrintMain();
       test.execute();

    }


    public void execute(){
        HelloWorld instance = new HelloWorld();
        instance.test(1,2);
    }


    public void updateClassFile(){
        String relative_path = "demo04/HelloWorld.class";
        String filepath = FileUtils.getFilePath(relative_path);
        byte [] bytes =  FileUtils.readBytes(filepath);

        ClassReader cr = new ClassReader(bytes);
        ClassWriter cw = new ClassWriter(cr,ClassWriter.COMPUTE_FRAMES);
        ClassVisitor cv = new RemoveMethodPrintVisitor(ASM9,cw);

        int parsingOptions = ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES;
        cr.accept(cv,parsingOptions);
        byte [] bytes2 = cw.toByteArray();
        FileUtils.writeBytes(filepath,bytes2);
    }
}
